


import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class NewPageWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _NewPageState();
  }

}

class _NewPageState extends State<NewPageWidget>{



  Timer? _timerCount;
  int _count = 0;
  int roomMaxTimer = 60;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _timerCount = Timer.periodic(const Duration(seconds: 1), (timer) {
      _count++;
      if(_count >= roomMaxTimer){
        _timerCount?.cancel();
        //退出语音室
        //退出语音 房间
        exitRoom();

      }
      print("_count === ${_count}");
    });
  }

  void exitRoom(){
    Navigator.of(context).pop();
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _timerCount?.cancel();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        body: Container(
          child: Center(
            child: InkWell(
              onTap: () async {
                bool? del = await showExitMeetingConfirmDialog();
                print("del ====== ${del}");
              },
              child: Text("adafdfadggg"),
            ),
          ),
        ),
      ),
    );
  }

  showExitMeetingConfirmDialog() {
    return showDialog<bool?>(
      context: context,
      builder: (context) {
        return AlertDialog(
          title: Text("提示"),
          content: Text("您确认退出吗?"),
          actions: <Widget>[
            TextButton(
              child: Text("取消"),
              onPressed: () => Navigator.of(context).pop(false),
            ),
            TextButton(
              child: Text("确认"),
              onPressed: () {
                //退出语音 房间
                Navigator.of(context).pop(true);
              },
            ),
          ],
        );
      },
    ).then((value) {
      print("value == ${value}");
      print("value == ${value}");
      return true;
    });
  }

}